package pong;

import java.awt.Rectangle;

import processing.core.PApplet;

public class PongBat extends MovableGameComponent {

	private int height;
	private int width;
	private Rectangle scopeOfMovement;

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public PongBat(final Vector2 position, final Rectangle scopeOfMovement,
			int height, int width) {
		super(position);
		this.width = width;
		this.height = height;
		this.scopeOfMovement = scopeOfMovement;
	}

	@Override
	public void draw(final PApplet applet) {
		applet.stroke(255);
		applet.rect(this.position.getX(), this.position.getY(),
				this.getWidth(), this.getHeight());
	}

	@Override
	public void move(float deltaX, float deltaY) {
		final Rectangle newPosition = new Rectangle((int) (this.position.getX()
				- this.width / 2 + deltaX), (int) (this.position.getY()
				- this.height / 2 + deltaY), width, height);
		if (scopeOfMovement.contains(newPosition)) {
			super.move(deltaX, deltaY);
		}
	}

	public Rectangle getBoundingBox() {
		return new Rectangle((int) (this.position.getX() - this.width / 2),
				(int) (this.position.getY() - this.height / 2), this.width,
				this.height);
	}
}
